version 18.0               // version control
set processors 8           // to ensure replicability across different numbers of cores
clear all                  // clear existing data
macro drop _all            // and macros, clean slate
set seed 20220801          // set seed

*-------------------------------------------------------
* project: daylight saving time (dst)
*-------------------------------------------------------

local pgm  "dst-data03_for_estimation_eastern_central" // file name
local who  "Muzhe Yang"                                // author
local dte  "2022-08-01"                                // created date
local dte2 "`c(current_date)'"                         // last run date
local tag  "`pgm'.do, created by `who' on `dte', last run on `dte2'"

capture log close
log using "code\management\\`pgm'.txt", replace text
display "`tag'"

use          "data_clean\places\dst-data01_places_2020_release_eastern_central_clean", clear
append using "data_clean\places\dst-data01_places_2021_release_eastern_central_clean"
sort TractFIPS wave
tab time_zone if CountyFIPS == "12045" // Gulf County, FL, has two time zones: Eatern and Central, https://www.timetemperature.com/us-county-fl/gulf-county-florida.shtml
gen GEOID = TractFIPS
compare GEOID TractFIPS
merge m:1 GEOID using "data_clean\acs\dst-data02_acs_combine"
drop if _merge == 2
drop GEOID State County _merge
merge m:1 CountyFIPS using "data_clean\solar\dst-data02_solar_county_avg"
drop if _merge == 2
drop _merge
order county_lon county_lat, before(centroid_lon)

replace dist_to_border = dist_to_border*0.000621371 // https://www.google.com/search?client=firefox-b-1-d&q=unit+converter (meter converted to mile)
label variable dist_to_border "distance between a census tract's centroid and the time zone border (in miles)"

sort TractFIPS wave
codebook, compact
compress
save "data_clean\\`pgm'.dta", replace 

log close
exit